<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>发布需求</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/html/issued/post_your_want_frm.css" />
    <style>

    </style>
</head>

<body>
    <div id="app">
        <div class="aui-content aui-margin-b-15">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">项目名称</div>
                        <div class="aui-list-item-input">
                            <input v-model="info.title" type="text" placeholder="请简短描述项目">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" @click="openWork()">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">项目工种</div>
                        <div class="aui-list-item-input">
                            <input v-model="info.work_cate_name" disabled type="text" placeholder="请选择">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" @click="openCity()">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">工作地点</div>
                        <div class="aui-list-item-input">
                            <input v-model="info.region" disabled type="text" placeholder="请选择">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">详细地址</div>
                        <div class="aui-list-item-input">
                            <input v-model="info.address" type="text" placeholder="请输入详细地址">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">用工时间</div>
                        <div class="aui-list-item-input">
                            <input v-model="info.work_date" type="date" placeholder="请选择">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">项目性质</div>
                        <div class="aui-list-item-input">
                            <div class="aui-list-item-input" style="display:flex;justify-content: flex-end;padding-right:0;">
                                <label><input class="aui-radio" type="radio" v-model="info.work_nature" value="1" name="demo1"> 承包制</label>
                                <label><input class="aui-radio" type="radio" v-model="info.work_nature" value="2" name="demo1"> 聘用制</label>
                            </div>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">金额预算</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.reward" placeholder="可选填，默认为面议">
                        </div>
                    </div>
                </li>

                <li class="aui-list-item" style="border-top:0.5rem solid #F6F6F6;">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">联系人</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.contact" placeholder="请输入姓名或昵称">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" style="border-bottom:0.5rem solid #F6F6F6;">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">联系人电话</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.contact_phone" placeholder="输入电话">
                        </div>
                    </div>
                </li>
            </ul>

            <div class="aui-content-padded">
                <div class="column_h">项目介绍</div>
                <textarea name="" id="" class="textarea" v-model="info.work_summary" placeholder="请输入文字介绍"></textarea>

                <div>
                    <div style="margin:1rem 0 0.5rem 0;">上传图片<small style="font-size:0.5rem;color:#B7B7B7;">(最多可上传三张图，每张图片大小不要超过2MB)</small></div>
                    <div class="up_image_box">
                        <div class="up_image" onclick="addImg(this,0)"><img src="../../image/icon/shangchuan.png" style="width:40%" alt=""></div>
                        <div class="up_image" onclick="addImg(this,1)"><img src="../../image/icon/shangchuan.png" style="width:40%" alt=""></div>
                        <div class="up_image" onclick="addImg(this,2)"><img src="../../image/icon/shangchuan.png" style="width:40%" alt=""></div>
                    </div>
                </div>

                <div class="column_h">其他要求</div>
                <textarea name="" id="" class="textarea" v-model="info.other_notes" placeholder="请输入文字介绍"></textarea>

                <div @click="submit()" class="btn">立即发布</div>
            </div>

        </div>
    </div>
</body>
<script src="../../script/api.js" charset="utf-8"></script>
<script src="../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../script/common/check.js" charset="utf-8"></script>
<script src="../../script/common/common.js" charset="utf-8"></script>
<script src="../../script/common/config.js" charset="utf-8"></script>
<script src="../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
        // $toast(api.pageParam.type);
    }

    var vm = new Vue({
        el: "#app",
        data: {
            info: {
                user_id: '',
                title: '',
                work_cate_id: '',
                work_cate_name: '',
                region_provinceid: '',
                region_cityid: '',
                region_areaid: '',
                region: '',
                work_nature: 1,
                address: '',
                work_date: '',
                reward: '',
                contact: '',
                contact_phone: '',
                work_summary: '',
                work_image_array: [],
                other_notes: '',
            }
        },
        methods: {
            init() {
                var userInfo = get_local('userInfo');
                this.info.user_id = userInfo.user_id;
            },
            submit() {
                if (!is_define(this.info.title)) {
                    $toast("请输入项目名称");
                    return;
                } else if (!is_define(this.info.work_cate_name)) {
                    $toast("请选择工种");
                    return;
                } else if (!is_define(this.info.region)) {
                    $toast("请选择工作地点");
                    return;
                } else if (!is_define(this.info.address)) {
                    $toast("请输入详细地址");
                    return;
                } else if (!is_define(this.info.work_date)) {
                    $toast("请选择工作时间");
                    return;
                } else if (!is_define(this.info.contact)) {
                    $toast("请输入联系人");
                    return;
                } else if (!is_define(this.info.contact_phone)) {
                    $toast("请输入联系人电话");
                    return;
                } else if (!checkMobile(this.info.contact_phone)) {
                    $toast("请输入正确的手机号");
                    return;
                } else if (!is_define(this.info.reward)) {
                    this.info.reward = 0;
                }

                _ajax(Config.api.FoundCreateSpecialty, this.info, function(ret) {
                    if (ret.code === 200) {
                        $toast("发布成功");
                        setTimeout(function() {
                            close_w();
                        }, 1000);
                    }
                });
            },
            openCity() {
                var url = '../city/city_win.html';
                api.openFrame({
                    name: 'mask',
                    url: url,
                    rect: {
                        x: 0,
                        y: api.winHeight - api.frameHeight,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)',
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                    }
                });
            },
            openWork() {
                var url = '../city/cate_win.html';
                api.openFrame({
                    name: 'mask',
                    url: url,
                    rect: {
                        x: 0,
                        y: api.winHeight - api.frameHeight,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)',
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                    }
                });
            },
        }
    });

    function setCity(province, city, area) {
        vm.info.region_provinceid = province.code;
        vm.info.region_cityid = city.code;
        vm.info.region_areaid = area.code;

        vm.info.region = province.name + '-' + city.name + '-' + area.name
    }

    function setWork(oParent, oChild) {
        vm.info.work_cate_name = oParent.work_cate_name + '/' + oChild.work_cate_name;
        vm.info.work_cate_id = oChild.work_cate_id;
    }

    function addImg(e, i) {
        imageUpload(Config.api.ImageUploadcommon, function(ret) {
            $(e).find('img').attr('src', ret.data.imgurl).css({'width': '100%', 'height': '100%'});
            vm.info.work_image_array[i] = ret.data.imgurl;
        });
    }
</script>

</html>
